<template>
  <el-container>
    <el-main>
      <el-table class="sa-table" :data="table.data" stripe>
        <el-table-column prop="id" label="ID" min-width="80" />
        <el-table-column label="名称" min-width="128">
          <template #default="scope">
            <div class="sa-table-line-1">
              {{ scope.row.title }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="类型" min-width="74">
          <template #default="scope">
            <div class="sa-table-line-1">
              {{ scope.row.type_text }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template #default="scope">
            <el-button class="is-link" type="primary" @click="modalCallBack(scope.row)"
              >选择</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </el-main>
    <el-footer class="sa-flex sa-row-right">
      <sa-pagination :pageData="pageData" @updateFn="getData" />
    </el-footer>
  </el-container>
</template>

<script>
  export default {
    name: 'ActivitySelect',
  };
</script>

<script setup>
  import { onMounted, reactive, ref } from 'vue';
  import { api } from '../activity.service';
  import { usePagination } from '@/sheep/hooks';

  const emit = defineEmits(['modalCallBack']);
  const props = defineProps(['modal']);

  const loading = ref(true);

  const table = reactive({
    data: [],
  });

  const { pageData } = usePagination();

  // 获取数据
  async function getData() {
    loading.value = false;
    const { data } = await api.activity.select(props.modal.params.type, {
      search: JSON.stringify({ status: ['noend'] }),
    });
    table.data = data.data;
    pageData.page = data.current_page;
    pageData.list_rows = data.per_page;
    pageData.total = data.total;
    loading.value = false;
  }

  function modalCallBack(row) {
    emit('modalCallBack', { event: 'confirm', data: row });
  }

  onMounted(() => {
    getData();
  });
</script>
